﻿
namespace FrameWorkSong
{
    public static class MathUtil
    {
        /// <summary>
        /// 16进制转10进制
        /// </summary>
        /// <param name="Sixteen"></param>
        /// <returns></returns>
        public static int SixteenNormalize(string Sixteen)
        {
            int normalize=0;
            char[] strCharArr = Sixteen.ToCharArray();
            for (int i = 0; i < strCharArr.Length; i++)
            {
                normalize += SixteenGetNumb(strCharArr[i].ToString());
            }
            return normalize;
        }
        static int SixteenGetNumb(string Numb)
        {
            switch (Numb)
            {
                case "0":
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                    return int.Parse(Numb);
                case "A":
                    return 10;
                case "a":
                    return 10;
                case "B":
                    return 11;
                case "b":
                    return 11;
                case "C":
                    return 12;
                case "c":
                    return 12;
                case "D":
                    return 13;
                case "d":
                    return 13;
                case "E":
                    return 14;
                case "e":
                    return 14;
                case "F":
                    return 15;
                case "f":
                    return 15;
                default:
                    return 0;
            }
        }
    }
}
